Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add iOS test verifying API can be reached in blocked state #6154

Conversation

niklasberglund
Copy link
Collaborator

@niklasberglund niklasberglund commented Apr 19, 2024

Implemented test verifying that API can still be reached when the app is in blocked state. A change affected the screenshot test so did a tiny modification of it as well.

To test the changes in this PR run testAPIReachableWhenBlocked under ConnectivityTests. Also testScreenshots was affected.


This change is Reviewable

@niklasberglund niklasberglund added the iOS Issues related to iOS label Apr 19, 2024
Copy link

linear bot commented Apr 19, 2024

Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 11 of 13 files at r1, all commit messages.
Reviewable status: 11 of 13 files reviewed, 1 unresolved discussion (waiting on @niklasberglund)


ios/MullvadVPNUITests/Pages/AccountPage.swift line 49 at r1 (raw file):

        guard let deviceName = deviceNameLabel.value as? String else {
            XCTFail("Failed to read device name from label")
            return String()

Is returning an empty String a common pattern in our codebase? To me, using an in-band value to represent out-of-band conditions feels like a code smell, and using a String? would be better. Are there ergonomic reasons for doing it this way?

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 11 of 13 files at r1, all commit messages.
Reviewable status: 11 of 13 files reviewed, 5 unresolved discussions (waiting on @acb-mv and @niklasberglund)


ios/MullvadVPN/View controllers/Settings/SettingsHeaderView.swift line 34 at r1 (raw file):

    let collapseButton: UIButton = {
        let button = UIButton(type: .custom)
        button.accessibilityIdentifier = .expandButton

Why change it to expandButton if its default position is collapsed ?


ios/MullvadVPNUITests/ConnectivityTests.swift line 49 at r1 (raw file):

    }

    /// Get the app into a blocked state by connecting to a relay then applying a filter which don't find this relay, then verify that app can still communicate by logging out and verifying that the device was successfully removed

nit
I'm surprised the comment length didn't trigger any linter violation 🤔


ios/MullvadVPNUITests/ConnectivityTests.swift line 65 at r1 (raw file):

            .tapApplyButton()

        // Select the first country, it's first city and it's first relay

nit
its instead of it's (the city / relay belongs to the parent item)


ios/MullvadVPNUITests/ConnectivityTests.swift line 67 at r1 (raw file):

        // Select the first country, it's first city and it's first relay
        SelectLocationPage(app)
            .tapCountryLocationCellExpandButton(withIndex: 0)

nit
while it's rather unlikely to happen, we should probably have some logic to guarantee we don't select a relay that's deactivated


ios/MullvadVPNUITests/Pages/AccountPage.swift line 49 at r1 (raw file):

Previously, acb-mv wrote…

Is returning an empty String a common pattern in our codebase? To me, using an in-band value to represent out-of-band conditions feels like a code smell, and using a String? would be better. Are there ergonomic reasons for doing it this way?

@acb-mv I think the return value here is just to satisfy the compiler since we mandate returning a string.
The execution of the test won't continue after this failure.

That being said, we can improve this function like so (and we can even include a custom error message if we want to be explicit about failure)

    func getDeviceName() throws -> String {
        let deviceNameLabel = app.otherElements[AccessibilityIdentifier.accountPageDeviceNameLabel]
        return try XCTUnwrap(deviceNameLabel.value as? String)
    }

Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 13 files at r1.
Reviewable status: all files reviewed, 5 unresolved discussions (waiting on @niklasberglund)

@niklasberglund niklasberglund force-pushed the verify-that-the-api-can-be-reached-when-the-app-is-blocked-ios-499 branch 2 times, most recently from 2f77765 to d8fb205 Compare April 25, 2024 13:39
Copy link
Collaborator Author

@niklasberglund niklasberglund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 11 of 13 files reviewed, 5 unresolved discussions (waiting on @acb-mv and @buggmagnet)


ios/MullvadVPN/View controllers/Settings/SettingsHeaderView.swift line 34 at r1 (raw file):

Previously, buggmagnet wrote…

Why change it to expandButton if its default position is collapsed ?

If it's in a collapsed state then the button will expand its content


ios/MullvadVPNUITests/ConnectivityTests.swift line 49 at r1 (raw file):

Previously, buggmagnet wrote…

nit
I'm surprised the comment length didn't trigger any linter violation 🤔

Me too!


ios/MullvadVPNUITests/ConnectivityTests.swift line 65 at r1 (raw file):

Previously, buggmagnet wrote…

nit
its instead of it's (the city / relay belongs to the parent item)

Haha, to this day I thought "its" and "it's" was the other way around so I've been using them the wrong way most of the time 😄


ios/MullvadVPNUITests/ConnectivityTests.swift line 67 at r1 (raw file):

Previously, buggmagnet wrote…

nit
while it's rather unlikely to happen, we should probably have some logic to guarantee we don't select a relay that's deactivated

Yes probably. This applies to other tests also. Been intentionally ignoring this flaw but maybe shouldn't for too long.


ios/MullvadVPNUITests/Pages/AccountPage.swift line 49 at r1 (raw file):

Previously, buggmagnet wrote…

@acb-mv I think the return value here is just to satisfy the compiler since we mandate returning a string.
The execution of the test won't continue after this failure.

That being said, we can improve this function like so (and we can even include a custom error message if we want to be explicit about failure)

    func getDeviceName() throws -> String {
        let deviceNameLabel = app.otherElements[AccessibilityIdentifier.accountPageDeviceNameLabel]
        return try XCTUnwrap(deviceNameLabel.value as? String)
    }

Yes exactly - don't want to return an optional here because it adds complexity without improving anything because the test has already failed and we're not trying to recover from being unable to read device name. I really should be using XCTUnrwap more. It's a good improvement, have implemented it 👍

Copy link
Collaborator Author

@niklasberglund niklasberglund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 11 of 13 files reviewed, 5 unresolved discussions (waiting on @acb-mv and @buggmagnet)


ios/MullvadVPNUITests/ConnectivityTests.swift line 67 at r1 (raw file):

Previously, niklasberglund (Niklas Berglund) wrote…

Yes probably. This applies to other tests also. Been intentionally ignoring this flaw but maybe shouldn't for too long.

Created a Linear ticket for this https://linear.app/mullvad/issue/IOS-654/handle-servers-being-down-in-end-to-end-tests

@niklasberglund niklasberglund force-pushed the verify-that-the-api-can-be-reached-when-the-app-is-blocked-ios-499 branch from d8fb205 to 3bd8f60 Compare April 30, 2024 08:03
Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 1 of 13 files at r1, 2 of 2 files at r2, 6 of 6 files at r3, all commit messages.
Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @acb-mv)

Copy link
Contributor

@buggmagnet buggmagnet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @acb-mv)

@niklasberglund niklasberglund force-pushed the verify-that-the-api-can-be-reached-when-the-app-is-blocked-ios-499 branch from 3bd8f60 to 98f7888 Compare May 6, 2024 11:28
Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r4, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

Copy link
Contributor

@acb-mv acb-mv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@buggmagnet buggmagnet force-pushed the verify-that-the-api-can-be-reached-when-the-app-is-blocked-ios-499 branch from 98f7888 to 4c4d8f2 Compare May 6, 2024 12:50
@buggmagnet buggmagnet merged commit 35e9180 into main May 6, 2024
7 checks passed
@buggmagnet buggmagnet deleted the verify-that-the-api-can-be-reached-when-the-app-is-blocked-ios-499 branch May 6, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
iOS Issues related to iOS
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants